<template>
  <layout title="">
    <a-form>
      <a-form-model-item label="选择导出的字段">
        <a-checkbox :indeterminate="indeterminate" v-model="checkAll">
          全选
        </a-checkbox>
        <a-checkbox-group v-model="currentSelected" :options="CheckboxOptions">
        </a-checkbox-group>
      </a-form-model-item>
      <a-form-model-item label="选择导出的格式">
        <a-radio-group v-model="currentType">
          <!-- <a-radio :value="0">按当前行政区下级行政区分组导出</a-radio>
          <a-radio :value="1">按当前行政区导出</a-radio> -->
          <a-radio :value="0">按选定行政区的下一级行政区名称分组导出</a-radio>
          <a-radio :value="1">按选定行政区导出</a-radio>
          <!-- <a-radio :value="2">按选定行政区的下一级行政区分组导出多个电子表文件</a-radio> -->
        </a-radio-group>
      </a-form-model-item>
    </a-form>
  </layout>
</template>

<script lang="ts">
import { Mixins, Component, Watch, Vue, Prop } from 'vue-property-decorator'
import EventsMixin from '@/mixin/events'
import { TableMixin, AuthMixin } from '@/mixin'

import { TableLayout } from '@/layouts'
import CustomForm from '@/components/src/Form'
import { publishServices, IPublish } from '@/common/services/publish'
import { userModule } from '@/store/modules/user'

@Component({
  components: {
    Layout: TableLayout,
    CustomForm,
  },
})
export default class AdminList extends Mixins(
  EventsMixin,
  TableMixin,
  AuthMixin
) {
  @Prop({
    type: Object,
  })
  public currentPub!: IPublish

  get isLarge() {
    return userModule.isLarge
  }

  get isNormal() {
    return userModule.isNormal
  }

  get isPlant() {
    return userModule.isPlant
  }

  public currentSelected = []

  public currentType = 0

  set checkAll(value: boolean) {
    // @ts-ignore
    this.currentSelected = value
      ? this.CheckboxOptions.map((options) => options?.value)
      : []
  }

  get indeterminate() {
    return (
      Boolean(this.currentSelected.length) &&
      this.currentSelected.length !== this.CheckboxOptions.length
    )
  }

  get checkAll() {
    return this.currentSelected.length === this.CheckboxOptions.length
  }

  get CheckboxOptions() {
    return this.columns
      .map((column) => column.children || column)
      .flat()
      .map((column) => {
        if (!column.key) return null
        return {
          label: column.title,
          value: column.key,
        }
      })
      .filter((_) => _)
  }

  // 产品列表表格信息
  public columns: ITable.IColumn[] = [
    {
      title: this.isLarge ? '大户编号' : '农户编号',
      dataIndex: 'member_id',
      key: 'member_id',
      width: 160,
    },
    {
      title: this.isLarge ? '大户名称' : '户主姓名',
      dataIndex: 'member_nam',
      key: 'member_nam',
      width: 120,
    },
    this.isLarge
      ? {
          title: '法人身份证',
          dataIndex: 'member_law_id',
          key: 'member_law_id',
          width: 120,
        }
      : {
          title: '身份证',
          dataIndex: 'member_sfz',
          key: 'member_sfz',
          width: 120,
        },
    this.isLarge
      ? {
          title: '法人身份证（不隐藏）',
          dataIndex: 'member_law_id_unhidden',
          key: 'member_law_id_unhidden',
          width: 120,
        }
      : {
          title: '身份证（不隐藏）',
          dataIndex: 'member_sfz_unhidden',
          key: 'member_sfz_unhidden',
          width: 120,
        },

    this.isLarge
      ? {
          title: '联系电话',
          dataIndex: 'big_mb_tel',
          key: 'big_mb_tel',
          width: 110,
        }
      : {
          title: '手机号',
          key: 'member_tel',
          dataIndex: 'member_tel',
          width: 200,
        },
    {
      title: this.isLarge ? '种粮地址' : '家庭地址',
      key: 's_a_nam_all',
      dataIndex: 's_a_nam_all',
      width: 200,
    },
    !this.isPlant
      ? {
          title: '确权面积（亩）',
          children: [
            {
              title: '合计',
              key: 'field',
              dataIndex: 'field',
              align: 'right',
              width: 120,
            },
            {
              title: '基础面积',
              key: 'field1',
              scopedSlots: { customRender: 'field1' },
              align: 'right',
              width: 100,
            },
            {
              title: '增加面积',
              key: 'field2',
              scopedSlots: { customRender: 'field2' },
              align: 'right',
              width: 100,
            },
            {
              title: '减少面积',
              key: 'field3',
              scopedSlots: { customRender: 'field3' },
              align: 'right',
              width: 100,
            },
          ],
        }
      : {},
    {
      title: '粮食种植面积(亩)',
      scopedSlots: { customRender: 'plant' },
      key: 'plant',
      align: 'right',
      width: 120,
    },

    ...(this.isNormal
      ? [
          {
            title: '确权面积（亩）',
            dataIndex: 'field_confirm_t',
            key: 'field_confirm_t',
            align: 'right',
            width: 100,
          },
          {
            title: '二包面积（亩）',
            dataIndex: 'field_confirm',
            key: 'field_confirm',
            align: 'right',
            width: 100,
          },
          {
            title: '计税面积（亩）',
            dataIndex: 'field_tax',
            key: 'field_tax',
            align: 'right',
            width: 100,
          },
        ]
      : []),

    {
      title: '补贴面积(亩)',
      dataIndex: 'bt_size',
      key: 'bt_size',
      align: 'right',
      width: 100,
    },
    {
      title: '补贴标准',
      dataIndex: 'pay_price',
      key: 'pay_price',
      align: 'right',
      width: 130,
    },
    {
      title: '补贴总金额（元）',
      dataIndex: 'pay_price_total',
      key: 'pay_price_total',
      align: 'right',
      width: 140,
    },
    {
      title: '收款账号',
      dataIndex: 'bank_num',
      key: 'bank_num',
      // scopedSlots: { customRender: 'bank_num' },
      width: 140,
    },
    {
      title: '收款账号（不隐藏）',
      dataIndex: 'bank_num_unhidden',
      key: 'bank_num_unhidden',
      // scopedSlots: { customRender: 'bank_num' },
      width: 140,
    },
    {
      title: '备注',
      dataIndex: 'readme',
      key: 'readme',
      width: 160,
    },
  ].filter((_) => _.title)
}
</script>

<style scoped lang="less">
.title {
  line-height: 30px;
  text-indent: 8px;
  span:nth-child(2) {
    margin: 0 10px;
  }
}
</style>
